package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.linlinjava.litemall.db.dao.LitemallBrandInvoiceMapper;
import org.linlinjava.litemall.db.domain.LitemallBrandInvoice;
import org.linlinjava.litemall.db.domain.LitemallBrandInvoiceExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @author: weilai
 * @date: 2019/12/11
 * @description:
 */
@Service
public class LitemallBrandInvoiceService {

    @Resource
    private LitemallBrandInvoiceMapper invoiceMapper;

    /**
     * 查：单表信息  id主键
     * @param id
     * @return
     */
    public LitemallBrandInvoice findById(Integer id){
        return invoiceMapper.selectByPrimaryKey(id);
    }

    /**
     * add :一个：给商户的票据brandInvoice
     * @param brandInvoice
     * @return
     */
    public int create(LitemallBrandInvoice brandInvoice){
       return invoiceMapper.insertSelective(brandInvoice);
     }

    /**
     * 更新一个：：给商户的对账单
     * @param brandInvoice
     * @return
     */
    public int updateInvoice(LitemallBrandInvoice brandInvoice){
        return invoiceMapper.updateByPrimaryKeySelective(brandInvoice);
    }


    /**
     * 根据brandID商户ID查：所有的票据  以添加时间 倒序
     * @param brandId
     * @return
     */
    public PageInfo<LitemallBrandInvoice> invoiceListByBrandId(Integer brandId, Integer page, Integer pageSize){
        PageHelper.startPage(page,pageSize);
        LitemallBrandInvoiceExample example = new LitemallBrandInvoiceExample();
        LitemallBrandInvoiceExample.Criteria criteria = example.createCriteria();
        criteria.andBrandIdEqualTo(brandId).andDeletedEqualTo(false);
        example.setOrderByClause("add_time" + " " + "desc");
        PageInfo<LitemallBrandInvoice> invoiceListByBrandId =(PageInfo<LitemallBrandInvoice> ) invoiceMapper.selectByExample(example);
        return invoiceListByBrandId;
    }
}
